/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ControlLayer;

import DBLayer.DBProduct;
import DBLayer.IFDBProduct;
import ModelLayer.Product;
import java.util.ArrayList;

/**
 *
 * @author Henrik-iMac
 */
public class CtrProduct {
    public CtrProduct(){
    }

    public ArrayList findAllProducts(boolean retrieveAssociation){
        IFDBProduct dbProd = new DBProduct();
        ArrayList allProd = new ArrayList();
        allProd = dbProd.getAllProducts(retrieveAssociation);
        return allProd;
    }

    public Product findProductByPartNo(int partNo, boolean retrieveAssociation){
        IFDBProduct dBProduct = new DBProduct();
        return dBProduct.findProductByPartNo(partNo, retrieveAssociation);
    }

    public Product findProductByName(String name, boolean  retrieveAssociation){
        IFDBProduct dBProduct = new DBProduct();
        return dBProduct.findProductByName(name, retrieveAssociation);
    }

    public int insertProduct(Product p){
        IFDBProduct dbProd = new DBProduct();
        return dbProd.insertProduct(p);
    }

    public int updateProduct(int partNo, String name, int amount, double purchasePrice,
            double salesPrice, double rentPrice, String countryOfOrigin,
            int minStock){
        IFDBProduct dbProd = new DBProduct();
        Product prodObj = new Product();
        prodObj.setPartNo(partNo);
        prodObj.setName(name);
        prodObj.setAmount(amount);
        prodObj.setPurchasePrice(purchasePrice);
        prodObj.setSalesPrice(salesPrice);
        prodObj.setRentPrice(rentPrice);
        prodObj.setCountryOfOrigin(countryOfOrigin);
        prodObj.setMinStock(minStock);

        return dbProd.updateProduct(prodObj);
    }

    public int updateProductAmount(int partNo, int amount){
        IFDBProduct dbProd = new DBProduct();
        Product prodObj = new Product();
        prodObj.setPartNo(partNo);
        prodObj.setAmount(amount);
        return dbProd.updateProductAmount(prodObj);
    }

    public int deleteProduct(int partNo){
        IFDBProduct dbProd = new DBProduct();
        return dbProd.deleteProduct(partNo);
    }
}
